<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function f(val) {
            var a = document.getElementById(val).value;
            var arr = a.split(",");
            var sum = 0;
            for (var i=0;i<arr.length;i++){
                sum+=parseInt(arr[i]);
            }
            alert(a+"的和是:"+sum);
        }
    </script>
</head>
<body>
    字符串(1,2,3):<input id="sz" type="text"><button style="margin-left: 2px" onclick="f('sz')">求和</button>
</body>
</html>